define(function(require,exports,module){
    var $ = require("$");
    function ImgExchange(imgId){
        this.$container = $("#"+imgId);
        this.$imgs = this.$container.find('.imgs');
        this.$vector = this.$container.find(".vectors");
        this.curIndex = 0;
    }
    module.exports = ImgExchange;

    ImgExchange.prototype.exchange = function(index){
        var that = this;
        this.$vector.find('li').eq(index).addClass('current').siblings('li').removeClass('current');
        that.$imgs.find('li').eq(index).stop().animate({'opacity':1},500).css({'z-index':1}).siblings('li').animate({'opacity':0},500).css({'z-index':0})
    }

    ImgExchange.prototype.run = function(){
        var that = this,timer;
        if(that.$container.length<=0) return;
        //点击切换
        this.$vector.find('li').click(function(){
            that.curIndex = $(this).index();
            that.exchange(that.curIndex);
        });
        //定时切换
        that.$container.hover(function(){
            clearInterval(timer);
        },function(){
            timer = setInterval(function(){
                var max = that.$imgs.find('li').length;
                that.curIndex++;
                if(that.curIndex>=max){
                    that.curIndex = 0;
                }
                that.exchange(that.curIndex);
            },3000);
        }).trigger("mouseout");

        //鼠标经过各个图片效果
        that.$imgs.find('li').each(function(){
            var $singleImgs = $(this).find('a');
            $singleImgs.hover(function(){
                $(this).siblings('a').find('.modal').show();
            },function(){
                $(this).siblings('a').find('.modal').hide();
            });
        });
    }
});